package service;

import com.github.pagehelper.PageHelper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import dao.ContractTypeMapper;
import domain.ContractModel;
import domain.ContractModelExample;
import domain.ContractType;
import domain.ContractTypeExample;

/**
 * User: xinxin
 * Date: 2016-10-27
 * Time: 22:15
 * FIXME
 */
@Service
public class ContractTypeServiceImp implements ContractTypeServiceI {
    @Autowired
    ContractTypeMapper mContractTypeMapper;

    @Override
    public ContractType selectTypeById(int id) {
        return mContractTypeMapper.selectByPrimaryKey(id);
    }

    @Override
    public ContractType selectTypeByTypeCode(String typeCode) {
        ContractTypeExample contractTypeExample = new ContractTypeExample();
        ContractTypeExample.Criteria criteria = contractTypeExample.createCriteria();
//        PageHelper.startPage(1, 10);
        criteria.andTypeCodeEqualTo(typeCode);
        contractTypeExample.or(criteria);
        return mContractTypeMapper.selectByExample(contractTypeExample).get(0);
    }

    @Override
    public List<ContractType> selectModelTypeAll(int pageIndex, int perPage) {
        PageHelper.startPage(pageIndex, perPage);
        return mContractTypeMapper.selectByExample(new ContractTypeExample());
    }

    @Override
    public List<ContractType> selectModelTypeAll(int pageIndex) {
        return selectModelTypeAll(pageIndex,10);
    }

    @Override
    public boolean newContractType(ContractType contractType) {

        return mContractTypeMapper.insert(contractType) > 0;
    }

    @Override
    public boolean updateContractType(ContractType contractType) {

        return mContractTypeMapper.updateByPrimaryKey(contractType) > 0;
    }

    @Override
    public boolean deleteContractType(ContractType contractType) {
        return mContractTypeMapper.deleteByPrimaryKey(contractType.getId()) > 0;
    }
}
